//
//  FXTHomeViewController.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/6/30.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "KindScrolleViewCell.h"
#import "UIImageView+AFNetworking.h"
@implementation KindScrolleViewCell
-(id)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        _vieww=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 200)];
        [self addSubview:_vieww];
        [self initView];
    }
    return self;
}
-(void)initView{
    
    _kindArray = [NSMutableArray new];
    self.backgroundColor=[UIColor whiteColor];
 
    
}
-(void)setKindArray:(NSMutableArray *)kindArray{
    [_kindArray removeAllObjects];
    [_kindArray addObjectsFromArray:kindArray];
    [_scrollView removeFromSuperview];
    //_scrollView=nil;
    _scrollView=[UIScrollView new];
    _scrollView.frame = CGRectMake(0, 0*kAppScale, self.width, self.height);
    _scrollView.showsHorizontalScrollIndicator = NO;
    [_vieww addSubview:_scrollView];
    
    
    float setX = 0;
    float setY = 0;
    float goodImageWith = self.width/5;
    for (int i=0; i<_kindArray.count; i++) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(setX,setY, goodImageWith, _scrollView.height/2)];
        view.backgroundColor = [UIColor whiteColor];
        view.tag = i;
        UITapGestureRecognizer *Tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapNew:)];
        [view addGestureRecognizer:Tap];
        [self.scrollView addSubview:view];
        
        NSDictionary *dic = [kindArray objectAtIndex:i];
        float imageViewWidth = 80/2.25*kAppScale;
        _kindImageView=[[UIImageView alloc] initWithFrame:CGRectMake(goodImageWith/2-imageViewWidth/2, 10*kAppScale, imageViewWidth, imageViewWidth)];
        [self.kindImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[dic objectForKey:@"worktype_img"]]] placeholderImage:[UIImage imageNamed:@"icon_toux"]];
        _kindImageView.contentMode = UIViewContentModeScaleToFill;
        _kindImageView.clipsToBounds = YES;
        [view addSubview:_kindImageView];
        
        _kindNameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, _kindImageView.bottom+10*kAppScale/2, view.width, 20*kAppScale)];
        _kindNameLabel.font=[UIFont systemFontOfSize:14*kAppScale];
        _kindNameLabel.textColor = [UIColor blackColor];
        _kindNameLabel.text=[NSString stringWithFormat:@"%@",[dic objectForKey:@"worktype_name"]];

        _kindNameLabel.textAlignment = 1;
        [view addSubview:_kindNameLabel];
        
        
        setX = view.right;
        
        if (setX >= SCREEN_WIDTH) {
            setX = 0;
            setY = view.bottom;
        }
        _scrollView.contentSize=CGSizeMake(SCREEN_WIDTH, self.height);
        
        
    }
    
}
-(void)TapNew:(UITapGestureRecognizer *)tap{
    if (_delegate && [_delegate respondsToSelector:@selector(KindScrolleViewCellDelegateClickEventWithIndex:)]) {
        NSInteger index=[[tap view] tag];
        [_delegate KindScrolleViewCellDelegateClickEventWithIndex:index];
    }
}
@end
